package gdonly.top.signin.widgets;

import android.app.Activity;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.HashMap;
import java.util.List;

import gdonly.top.signin.R;

/**
 * Created by zhuzhuxia on 2017/5/14.
 */
public class ShowRecordsByStuAdapter extends RecyclerView.Adapter<ViewHolder1> {
    private List<HashMap<String,Object>> mData;
    private Activity context;
    public ShowRecordsByStuAdapter(List<HashMap<String, Object>> list, Activity context){
        mData = list;
        this.context=context;
    }
    @Override
    public ViewHolder1 onCreateViewHolder(ViewGroup parent, int viewType) {
        View linearLayout = LayoutInflater.from(context).inflate(R.layout.item_querybystu_records, parent, false);
//        = LinearLayout.inflate();
        ViewHolder1 viewHolder=new ViewHolder1(linearLayout,context);
        return viewHolder;
    }


    @Override
    public void onBindViewHolder(ViewHolder1 holder, int position) {


        if(mData!=null) {
            Log.e("TAG", "settext....");
            holder.courseNameTv.setText((String) mData.get(position).get("course_name"));
            holder.dateTv.setText((String) mData.get(position).get("date"));

            if((boolean)mData.get(position).get("state") == false){
                holder.courseNameTv.setTextColor(context.getResources().getColor(R.color.light_red));
                holder.dateTv.setTextColor(context.getResources().getColor(R.color.light_red));

            }
            else if((boolean)mData.get(position).get("state") == true){
                holder.courseNameTv.setTextColor(context.getResources().getColor(R.color.light_green));
                holder.dateTv.setTextColor(context.getResources().getColor(R.color.light_green));
            }
        }
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }
}
class ViewHolder1 extends RecyclerView.ViewHolder{

    public TextView dateTv;
    public TextView courseNameTv;

    private Activity context;


    public ViewHolder1(View itemView,Activity context) {
        super(itemView);
        this.context=context;
        courseNameTv = (TextView) itemView.findViewById(R.id.courseinrecord_name_tv);
        dateTv= (TextView) itemView.findViewById(R.id.dateinrecord_tv);
    }

}